package org.scboy.gateway.filters;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * 跨域过滤器
 * @author 杨浩
 */
@Configuration
public class WsmCorsWebFilter {
	
	/**
	 * 跨域处理
	 * @return
	 */
	@Bean
	public CorsWebFilter corsWebFilter() {
		
		System.out.println("调用CcorsWebFilter");
		
		UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
		CorsConfiguration configuration=new CorsConfiguration();
		//允许跨域的请求头
		configuration.addAllowedHeader("*");
		//允许跨域的请求方法
		configuration.addAllowedMethod("*");
		//允许跨域匹配
		configuration.addAllowedOriginPattern("*");
		//允许证书
		configuration.setAllowCredentials(true);
		source.registerCorsConfiguration("/**", configuration);
		return new CorsWebFilter(source);
	}
	
	
}
